<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>WISSC轮滑教培服务网-查询系统</title>
    <#assign base=request.contextPath  />
    <link rel="icon" href="${base}/favicon.ico">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <link rel="stylesheet" href="${base}/frame/layui/css/layui.css">
    <script src="${base}/frame/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${base}/js/ztree/jquery-1.4.4.min.js"></script>
    <script src="${base}/js/jquery.min.js"></script>
    <script type="text/javascript" src="${base}/js/feng.js"></script>
    <link rel="stylesheet" type="text/css" href="${base}/css/hzw-city-picker.css">
    <script type="text/javascript" src="${base}/js/city-data.js"></script>
    <script type="text/javascript" src="${base}/js/hzw-city-picker.min.js"></script>
    <script type="text/javascript" src="${base}/js/city-zk.js"></script>
    <script type="text/javascript" src="${base}/js/province.js"></script>
</head>
<script>
    var defaults = {
        s1: 'provid',
        s2: 'cityid',
        s3: 'areaid',
        v1: null,
        v2: null,
        v3: null
    };
</script>
<body>
<form class="layui-form" style="margin: 10px">

    <input type="hidden" id="id" value="${id}"/>
    <input type="hidden" id="stuId" value="${stuId}"/>
    <div class="layui-form-item">
        <label class="layui-form-label"><a style="color:red">*</a>&nbsp;姓名</label>
        <div class="layui-input-inline">
            <input name="name" id="name" lay-verify="required" autocomplete="off" class="layui-input isNull"
                   type="text">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label"><a style="color:red">*</a>&nbsp;性别</label>
        <div class="layui-input-block">
            <input type="radio" id="man" name="sex" value="1" title="男" checked>
            <input type="radio" id="wuman" name="sex" value="2" title="女">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><a style="color:red">*</a>&nbsp;身份证号</label>
        <div class="layui-input-inline">
            <input name="idNumber" id="idNumber" lay-verify="required" autocomplete="off" class="layui-input isNull"
                   type="text">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label"><a style="color:red">*</a>&nbsp;注册时间</label>
        <div class="layui-input-inline">
            <input name="regTime" id="regTime" lay-verify="required" autocomplete="off" class="layui-input isNull"
                   type="text">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label"><a style="color:red">*</a>&nbsp;选择地区</label>
            <div class="layui-input-inline">
                <select name="provid" id="provid" lay-filter="provid" lay-verify="required" class="isNull">
                    <option value="">请选择国家</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <select name="cityid" id="cityid" lay-filter="cityid" lay-verify="required">
                    <option value="">请选择省</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <select name="areaid" id="areaid" lay-filter="areaid" lay-verify="required">
                    <option value="">请选择市</option>
                </select>
            </div>
        </div>
    </div>
    <div class="layui-form-item" id="demo"></div>
    <div class="layui-form-item">
        <div class="layui-input-inline">
            <button class="layui-btn" lay-submit lay-filter="formDemo" type="button" onclick="onSubmit()"
                    id="aa" style="background-color: #0092EF;">立即提交
            </button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
        <input hidden id="cc">
    </div>
</form>
</body>
<script>
    var idFlag = 0;
    var cc = "";
    var ids = $("#id").val();
    var fileIds = [];
    layui.use('upload', function () {
        var $ = layui.jquery
            , upload = layui.upload;


        $(function () {

            $.ajax({
                type: "POST",
                traditional: true,//这里设置为true,不然后台接收到的参数会带上[]，导致数据无法正常接收
                url: "${base}/student/getTeamCity",
                data: {id: $("#id").val()},
                success: function (data) {
                    var arr = data.str.split("/");
                    var arr1 = data.sum.split("@");
                    for (var i = 0; i < arr1.length - 1; i++) {
                        var arr2 = arr1[i].split(",");
                        if (arr2[0] != "null") {
                            for (var j = 0; j < 1; j++) {
                                $("#demo").append(
                                    '<div class="layui-form-item">' +
                                    '        <label class="layui-form-label"><a style="color:red">*</a>&nbsp;科目选择</label>' +
                                    '        <div class="layui-input-inline">' +
                                    '<input id= "stuId' + idFlag + '" type="hidden" value= "' + arr2[0] + '"/>' +
                                    '            <select name="subject " lay-verify="required" id="subject' + idFlag + '" class=" isNull">' +
                                    '                <option value="">请选科目</option>' +
                                    '                <option value="1">基础滑轮</option>' +
                                    '                <option value="2">速度滑轮</option>' +
                                    '                <option value="3">自由式滑轮</option>' +
                                    '                <option value="4">轮滑球</option>' +
                                    '                <option value="5">极限滑轮</option>' +
                                    '                <option value="6">陆地滑雪(滑轮)</option>' +
                                    '            </select>' +
                                    '        </div>' +
                                    '    </div>' +
                                    '    <div class="layui-form-item">' +
                                    '        <label class="layui-form-label"><a style="color:red">*</a>&nbsp;等级选择</label>' +
                                    '        <div class="layui-input-inline">' +
                                    '            <select name="subjectLevel" lay-verify="required" id="subjectLevel' + idFlag + '" class=" isNull">' +
                                    '                <option value="">请选等级</option>' +
                                    '                <option value="1">1级</option>' +
                                    '                <option value="2">2级</option>' +
                                    '                <option value="3">3级</option>' +
                                    '                <option value="4">4级</option>' +
                                    '                <option value="5">5级</option>' +
                                    '                <option value="6">6级</option>' +
                                    '                <option value="7">7级</option>' +
                                    '                <option value="8">8级</option>' +
                                    '                <option value="9">9级</option>' +
                                    '                <option value="10">10级</option>' +
                                    '            </select>' +
                                    '        </div>' +
                                    '    </div>' +
                                    '    <div class="layui-form-item">' +
                                    '        <label class="layui-form-label"><a style="color:red">*</a>&nbsp;证件编号</label>' +
                                    '        <div class="layui-input-inline">' +
                                    '            <input type="text"  name="idNo" value="' + arr2[4] + '" id="idNo' + idFlag + '"lay-verify="required" autocomplete="off" class="layui-input">' +
                                    '        </div>' +
                                    '    </div>' +
                                    '    <div class="layui-upload">' +
                                    '<input style="display:none" type="file" onchange="MyUpload(' + idFlag + ')" id="file' + idFlag + '"/>' +
                                    '        <button type="button" onclick="clickFile(' + idFlag + ')" class="layui-btn" id="test' + idFlag + '" style="background-color: #0092EF;margin: 10px">上传证书</button><br>' +
                                    '        <blockquote class="layui-elem-quote layui-quote-nm" style="width: 85%;height: 842px;float: left">' +
                                    '            证书文件：' +
                                    '            <img id="demo1' + idFlag + '" src="${base}/team/getPhoto?path=' + arr2[3] + '" style="width:595px;height:842px"/>' +
                                    '            <div class="layui-upload-list " id="demoImage' + idFlag + '" ></div>' +
                                    '        </blockquote>' +
                                    '    </div>')
                                $("#subject" + idFlag).val(arr2[1]);
                                $("#subjectLevel" + idFlag).val(arr2[2]);
                                idFlag += 1;
                                cc += arr2[3] + ","
                            }
                        } else {
                            break;
                        }
                    }
                    if (arr != null && arr != "") {
                        for (var i = 0; i < arr.length; i++) {
                            if (i == 0) {
                                $("#provid").find("option:contains('" + arr[i] + "')").attr("selected", true);
                            }
                            if (i == 1) {
                                $("#cityid").append("<option selected='selected' value='" + arr[i] + "' >" + arr[i] + "</option>");
                            }
                            if (i == 2) {
                                $("#areaid").append("<option selected='selected' value='" + arr[i] + "' >" + arr[i] + "</option>");
                            }
                        }
                    }
                    form.render('select');
                }
            });
        })

    })
</script>
<script type="text/javascript">

    var cityPicker = new HzwCityPicker({
        data: data,
        target: 'cityChoice',
        valType: 'k',
        hideCityInput: {
            name: 'city',
            id: 'city'
        },
        hideProvinceInput: {
            name: 'areaId',
            id: 'areaId',
            val: 'q'
        },
        callback: function () {
        }
    });

    cityPicker.init();

    layui.use(['form', 'layedit', 'laydate', 'layer'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
        //日期插件
        laydate.render({
            elem: '#regTime'
        });
    });
    var bb = "";

    //编辑
    function onSubmit() {
        if (fileIds == "") {
            fileIds = "kk";
        }
        if (!isNull()) {
            return;
        }
        var provid = $("#provid").val()
        var cityid = $("#cityid").val();
        var areaid = JSON.stringify($("#areaid").val());
        var str = areaid.replace(/^\"|\"$/g, '');
        var sum = provid + "/" + cityid + "/" + str + "/";
        var jsonData = {};
        jsonData.name = $("#name").val();
        jsonData.sex = $('input:radio[name="sex"]:checked').val();
        jsonData.idNumber = $("#idNumber").val();
        jsonData.city = sum;
        jsonData.regTime = (new Date($("#regTime").val())).getTime();
        //id
        jsonData.id = $("#id").val();
        for (var i = 0; i < idFlag; i++) {
            var subject = subject + i;
            var stuId = stuId + i;
            var subjectLevel = subjectLevel + i;
            var idNo = idNo + i;
            stuId = $("#stuId" + i).val();
            subject = $("#subject" + i).val();
            subjectLevel = $("#subjectLevel" + i).val();
            idNo = $("#idNo" + i).val();
            bb += stuId + "," + subject + "," + subjectLevel + "," + idNo + "@";
        }
        $.ajax({
            type: "POST", //提交方式
            traditional: true,//这里设置为true,不然后台接收到的参数会带上[]，导致数据无法正常接收
            url: "${base}/student/updateById",
            data: {pIds: fileIds, param1: JSON.stringify(jsonData), param2: bb},
            success: function (data) {
                if (data.code === 0) {
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                    var table = parent.layui.table;
                    //表刷新方法
                    table.reload('testReload', {
                        url: '${base}/student/selectMyPage'//数据接口
                        , where: {} //设定异步数据接口的额外参数
                        //,height: 300
                    });
                } else {
                    layer.msg(data.msg)
                }
            }
        });
    }


    function clickFile(flag) {
        $("#file" + flag).click();
    }

    function MyUpload(flag) {
        var fd = new FormData();
        fd.append("file", $('#file' + flag)[0].files[0]);
        fd.append("subject", $("#subject" + flag).val());
        fd.append("subjectLevel", $("#subjectLevel" + flag).val());
        fd.append("stuId", $("#stuId" + flag).val());
        fd.append("idNo", $("#idNo" + flag).val());
        //上传文件ajax
        $.ajax({
            async: false,
            cache: false,
            type: "post",
            data: fd,
            url: '/student/updateimageUrl',
            contentType: false, //必须
            processData: false, //必须
            success: function (res) {
                //上传成功
                if (res.code == 0) {
                    $("#demo1" + flag).remove();
                    $('#demoImage' + flag).html($('#file' + flag).val())
                    fileIds.push(res.data.fileId)
                }
            }
        })
    }
</script>
</html>
